package com.zyj.okhttp;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        OkHttpClient okHttpClient = new OkHttpClient() ;
        Request request = new Request.Builder()
                .get()
                .url( "https:www.baidu.com" )
                .build() ;
       Call call =  okHttpClient.newCall( request ) ;

       /* try {
            //同步请求
            Response response  = call.execute() ;
        } catch (IOException e) {
            e.printStackTrace();
        }*/

        //异步执行
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {

            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {

            }
        });
    }
}
